package com.ky.client.util;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import org.omg.CORBA.Request;

import com.ky.common.dto.Dto;

public class RequestUtil<T> {
	
	private Socket clientSocket;
	private ObjectOutputStream oos;
	private ObjectInputStream ois;
	
	public RequestUtil() {
		try {
			clientSocket=new Socket(PropertiesUtil.getProperty(ConfigConstants.SERVER_HOST_KEY),Integer.parseInt(PropertiesUtil.getProperty(ConfigConstants.SERVER_PORT_KEY)));
			oos=new ObjectOutputStream(clientSocket.getOutputStream());
			ois=new ObjectInputStream(clientSocket.getInputStream());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Dto request(Dto<T> requestDto) {
		Dto responseDto=null;
		try {
			oos.writeObject(requestDto);
			responseDto = (Dto) ois.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return responseDto;
	}

}
